package com.wangyonghao.harmonyocrs.utils;

import com.wangyonghao.harmonyocrs.ResourceTable;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

public class ToastUtils {
    public static void showDialog(Context context,String message) {
        DirectionalLayout dl = (DirectionalLayout) LayoutScatter.getInstance(context).parse(ResourceTable.Layout_utils_toast, null, false);

        Text msg = (Text) dl.findComponentById(ResourceTable.Id_msg);

        msg.setText(message);

        ToastDialog td = new ToastDialog(context);
        td.setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
        td.setDuration(2000);
        td.setAlignment(LayoutAlignment.BOTTOM);
        td.setContentCustomComponent(dl);
        //将吐司弹窗显示位置从底部向上偏移200像素
        td.setOffset(0, 200);
        td.show();
    }
}
